//
//  YYPacjageVC.m
//  drivingSchool
//
//  Created by 子yu 刘 on 2018/9/12.
//  Copyright © 2018年 子yu 刘. All rights reserved.
//

#import "YYPacjageVC.h"
#import "YYPackageCell.h"
#import "YYMemberDetailVC.h"

@interface YYPacjageVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,strong)NSArray * dataArr;

@end

@implementation YYPacjageVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getData];
}

-(void)getData{
    [RequestOperationManager giftList_success:^(id result) {
        if (DEF_REQ_SUCCESS) {
            self.dataArr = result[@"data"][@"list"];
            [self.tableView reloadData];
        }
        
    } failture:^(NSError *error) {
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArr.count;;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YYPackageCell * cell = [tableView dequeueReusableCellWithIdentifier:@"YYPackageCell"];
    NSDictionary * itme = self.dataArr[indexPath.row];
    
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",DEF_INTERFACE_WEBVIEWSERVICE,itme[@"image"]]]];
    cell.lbName.text = itme[@"name"];
    cell.lbSource.text = [NSString stringWithFormat:@"可获积分：%@积分",itme[@"integral"]];
    cell.lbPrice.text = itme[@"price"];
    NSArray * goodsArr = itme[@"goods"];
    cell.lbcontent.text = [NSString stringWithFormat:@"礼包套餐：%@",[goodsArr componentsJoinedByString:@","]];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    YYMemberDetailVC * detail = (YYMemberDetailVC *)[CFUtility getVC:@"YYMemberDetailVC" Storyboard:PACKAGE];
    detail.pid = self.dataArr[indexPath.row][@"id"];
    [self.navigationController pushViewController:detail animated:YES];
}

-(NSArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSArray array];
    }
    return _dataArr;
}

@end
